package com.ticket.sass.provider.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * MyBatis-Plus 数据填充 设置
 * @author ywb
 * @date 2021-11-23 11:30
 */
@Component
public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
    /**
     * 新增时填充
     */
    @Override
    public void insertFill(MetaObject obj) {
        this.strictInsertFill(obj, "createdAt", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(obj, "updatedAt", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(obj, "tenantId", Integer.class, 1);
    }

    /**
     * 修改时填充
     */
    @Override
    public void updateFill(MetaObject obj) {
        this.setFieldValByName( "updatedAt", LocalDateTime.now(), obj);
    }
}
